home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir31 / gus_prog.zip / SAMPLE.ASM < prev   
Assembly Source File  |  1993-01-19  |  18KB  |  746 lines

  1. ; By Joshua Jensen
  2. ;
  3. ; I realize this isn't the most efficiently coded piece of work, but I was in
  4. ; a hurry, so you'll have to deal with it!
  5.  
  6. ideal
  7. P286
  8. model   Huge
  9. jumps
  10.  
  11. stack   1024
  12.  
  13. codeseg
  14.  
  15.                 assume  cs:@code,ds:MyData
  16.  
  17. Base    dw      220h
  18.  
  19. proc    UDelay
  20.         push    dx ax
  21.         mov     dx,300h
  22.         in      al,dx
  23.         in      al,dx
  24.         in      al,dx
  25.         in      al,dx
  26.         in      al,dx
  27.         in      al,dx
  28.         in      al,dx
  29.         pop     ax dx
  30.         ret
  31. endp    UDelay
  32.  
  33. ; BX:CX Set to whatever.
  34. proc    U_Peek
  35.         push    dx
  36.         mov     dx,[cs:Base]
  37.         add     dx,103h                 ; 103h
  38.         mov     al,43h
  39.         out     dx,al
  40.         inc     dx                      ; 104h
  41.         mov     ax,cx
  42.         out     dx,ax
  43.         dec     dx                      ; 103h
  44.         mov     al,44h
  45.         out     dx,al
  46.         add     dx,2
  47.         mov     al,bl
  48.         out     dx,al
  49.         add     dx,2
  50.         in      al,dx
  51.         pop     dx
  52.         ret
  53. endp    U_Peek
  54.  
  55. ; BX:CX Set to whatever.
  56. ; AX Value to poke
  57. proc    U_Poke
  58.         push    dx ax
  59.         mov     dx,[cs:Base]
  60.         add     dx,103h
  61.         mov     al,43h
  62.         out     dx,al
  63.         inc     dx
  64.         mov     ax,cx
  65.         out     dx,ax
  66.         dec     dx
  67.         mov     al,44h
  68.         out     dx,al
  69.         add     dx,2
  70.         mov     al,bl
  71.         out     dx,al
  72.         add     dx,2
  73.         pop     ax
  74.         out     dx,al
  75.         pop     dx
  76.         ret
  77. endp    U_Poke
  78.  
  79.  
  80. ; DX - Base.
  81. proc    U_Probe
  82.         mov     dx,[cs:Base]
  83.         add     dx,0103h                ; 103h
  84.         mov     al,4Ch
  85.         out     dx,al
  86.         add     dx,2                    ; 105h
  87.         mov     al,0
  88.         out     dx,al
  89.         call    UDelay
  90.         call    UDelay
  91.         sub     dx,2                    ; 103h
  92.         mov     al,4Ch
  93.         out     dx,al
  94.         add     dx,2                    ; 105h
  95.         mov     al,1
  96.         out     dx,al
  97.         mov     ax,0AAh
  98.         mov     bx,0
  99.         mov     cx,0
  100.         call    U_Poke
  101.         mov     ax,055h
  102.         mov     bx,1
  103.         call    U_Poke
  104.         mov     bx,0
  105.         call    U_Peek
  106.         push    ax
  107.         mov     ax,0
  108.         call    U_Poke
  109.         sub     dx,2                    ; 103h
  110.         mov     al,4Ch
  111.         out     dx,al
  112.         add     dx,2                    ; 105h
  113.         mov     al,0
  114.         out     dx,al
  115.         pop     ax
  116.         cmp     al,0AAh
  117.         jnz     @@Nope
  118.         clc
  119.         ret
  120. @@Nope: stc
  121.         ret
  122. endp    U_Probe
  123.  
  124. proc    U_Reset
  125.         mov     dx,[cs:Base]
  126.         add     dx,103h                 ; 103h
  127.         mov     al,4Ch                  ; Turns on memory writes.
  128.         out     dx,al
  129.         add     dx,2                    ; 105h
  130.         mov     al,1
  131.         out     dx,al
  132.         call    UDelay
  133.         sub     dx,2
  134.         mov     al,4Ch                  ; ???  The samples won't play without it.
  135.         out     dx,al
  136.         add     dx,2                    ; 105h
  137.         mov     al,7
  138.         out     dx,al
  139.         sub     dx,2
  140.         mov     al,0Eh                  ; Turn off stereo (or something).
  141.         out     dx,al                   ; Try taking it out and running PlayFile.
  142.         add     dx,2
  143.         mov     al,0dfh
  144.         out     dx,al
  145.  
  146.         mov     cx,0                    ; Voice Number
  147. @@VoiceLoop:
  148.         mov     dx,[cs:Base]
  149.         add     dx,102h                 ; 102h
  150.         mov     al,cl
  151.         out     dx,al
  152.         inc     dx                      ; 103h
  153.         mov     al,0
  154.         out     dx,al
  155.         add     dx,2                    ; 105h
  156.         mov     al,3
  157.         out     dx,al
  158.         sub     dx,2                    ; 103h
  159.         inc     cx
  160.         cmp     cx,32
  161.         jl      @@VoiceLoop
  162.         ret
  163. endp    U_Reset
  164.  
  165.  
  166. ; Returns:
  167. ;   0 = No Ram
  168. ;   1 = 256k
  169. ;   2 = 512k
  170. ;   3 = 768k
  171. ;   4 = 1024k
  172. proc    U_SizeDRAM
  173.         mov     bx,0
  174.         mov     cx,0
  175. @@DRAMLoop:
  176.         push    cx
  177.         mov     cx,0
  178.         mov     ax,0AAh
  179.         call    U_Poke
  180.         call    U_Peek
  181.         pop     cx
  182.         cmp     al,0AAh
  183.         jnz     @@Exit
  184.         add     bx,4
  185.         inc     cx
  186.         cmp     cx,4
  187.         jbe     @@DRAMLoop
  188. @@Exit: mov     ax,cx
  189.         ret
  190. endp    U_SizeDRAM
  191.  
  192. ; BX - Voice
  193. ; AX - Frequency
  194. proc    U_SetFreq               ; Close enough for me...
  195.         xor     dx,dx
  196.         mov     cx,19
  197.         div     cx
  198.         push    ax
  199.         mov     dx,[cs:Base]
  200.         add     dx,102h         ; 102h
  201.         mov     ax,bx
  202.         out     dx,al
  203.         inc     dx              ; 103h
  204.         mov     al,1
  205.         out     dx,al
  206.         inc     dx              ; 104h
  207.         pop     ax
  208.         out     dx,ax
  209.         ret
  210. endp    U_SetFreq
  211.  
  212.  
  213. ; AX - Voice
  214. ; BX - Balance (0-f) 7 is middle
  215. proc    U_SetBalance
  216.         mov     dx,[cs:Base]
  217.         add     dx,102h
  218.         out     dx,al
  219.         inc     dx
  220.         mov     al,0ch
  221.         out     dx,al
  222.         add     dx,2
  223.         mov     ax,bx
  224.         out     dx,al
  225.         ret
  226. endp    U_SetBalance
  227.  
  228. ; AX - Voice
  229. ; BX - Volume
  230. proc    U_SetVolume
  231.         mov     dx,[cs:Base]
  232.         add     dx,102h
  233.         out     dx,al
  234.         inc     dx
  235.         mov     al,9
  236.         out     dx,al
  237.         inc     dx
  238.         mov     ax,bx
  239.         out     dx,ax
  240.         ret
  241. endp    U_SetVolume
  242.  
  243. ; AX - Voice
  244. ; BX - Mode
  245. ;          bit 0: 0=voice on (along with bit 1)
  246. ;          bit 1: 0=voice on (along with bit 0)
  247. ;          bit 2: 0=8 bit data, 1=16 bit data
  248. ;          bit 3: 0=No loop, 1=Loop
  249. ;          bit 4: 0=Go forward, 1=Go backward
  250. proc    U_SetLoopMode
  251.         mov     dx,[cs:Base]
  252.         add     dx,102h
  253.         out     dx,al
  254.         inc     dx
  255.         mov     al,80h
  256.         add     dx,2
  257.         in      al,dx
  258.         mov     bh,al
  259.         sub     dx,2
  260.         xor     al,al
  261.         out     dx,al
  262.         add     dx,2
  263.         and     bh,0e7h
  264.         or      bh,bl
  265.         mov     al,bh
  266.         out     dx,al
  267.         ret
  268. endp    U_SetLoopMode
  269.  
  270. ; AX - Voice
  271. proc    U_StopVoice
  272.         mov     dx,[cs:Base]
  273.         add     dx,102h
  274.         out     dx,al
  275.         inc     dx
  276.         mov     al,80h
  277.         add     dx,2
  278.         in      al,dx
  279.         mov     bh,al
  280.         sub     dx,2
  281.         xor     al,al
  282.         out     dx,al
  283.         add     dx,2
  284.         mov     al,bh
  285.         and     bh,0dfh
  286.         or      al,3
  287.         out     dx,al
  288.         call    UDelay
  289.         sub     dx,2
  290.         xor     al,al
  291.         out     dx,al
  292.         add     dx,2
  293.         mov     al,bh
  294.         and     bh,0dfh
  295.         or      al,3
  296.         out     dx,al
  297.         ret
  298. endp    U_StopVoice
  299.  
  300.  
  301.  
  302. SampleBegin     dd      0       ; (Start location in DRAM, apparently 32-byte aligned)
  303. SampleStart     dd      0       ; (Start location of loop)
  304. SampleEnd       dd      0       ; (End of sample)
  305.  
  306. ; AX - Voice
  307. ; BX - Mode
  308. proc    U_StartVoice
  309.         push    bx
  310.         mov     dx,[cs:Base]
  311.         add     dx,102h         ; 102h
  312.         out     dx,al
  313.  
  314.         ; Send sample begin
  315.         inc     dx              ; 103h
  316.         mov     al,0ah
  317.         out     dx,al
  318.         inc     dx              ; 104h
  319.         mov     ax,[Word cs:SampleBegin]
  320.         mov     cx,[Word cs:SampleBegin+2]
  321.         call    RShift
  322.         out     dx,ax
  323.         dec     dx              ; 103h
  324.         mov     al,0bh
  325.         out     dx,al
  326.         inc     dx              ; 104h
  327.         mov     ax,[Word cs:SampleBegin]
  328.         shl     ax,9
  329.         out     dx,ax
  330.         dec     dx              ; 103h
  331.  
  332.         ; Send sample start
  333.         mov     al,2
  334.         out     dx,al
  335.         inc     dx              ; 104h
  336.         mov     ax,[Word cs:SampleStart]
  337.         mov     cx,[Word cs:SampleStart+2]
  338.         call    RShift
  339.         out     dx,ax
  340.         dec     dx              ; 103h
  341.         mov     al,3
  342.         out     dx,al
  343.         inc     dx              ; 104h
  344.         mov     ax,[Word cs:SampleStart]
  345.         shl     ax,9
  346.         out     dx,ax
  347.         dec     dx              ; 103h
  348.  
  349.         ; Send sample end
  350.         mov     al,4
  351.         out     dx,al
  352.         inc     dx              ; 104h
  353.         mov     ax,[Word cs:SampleEnd]
  354.         mov     cx,[Word cs:SampleEnd+2]
  355.         call    RShift
  356.         out     dx,ax
  357.         dec     dx              ; 103h
  358.         mov     al,5
  359.         out     dx,al
  360.         inc     dx              ; 104h
  361.         mov     ax,[Word cs:SampleEnd]
  362.         shl     ax,9
  363.         out     dx,ax
  364.         dec     dx              ; 103h
  365.  
  366.         mov     al,0
  367.         out     dx,al
  368.         pop     ax
  369.         add     dx,2            ; 105h
  370.         out     dx,al
  371.         ret
  372. endp    U_StartVoice
  373.  
  374.  
  375. ; CX:AX  - Number
  376. proc    RShift
  377.         mov     bx,cx
  378.         shr     ax,7
  379.         shr     cx,7
  380.         shl     bx,9
  381.         or      ax,bx
  382.         ret
  383. endp    RShift
  384.  
  385. ; AX - Voice
  386. ; Returns:  DX:AX - Position
  387. proc    U_ReadPos
  388.         mov     dx,[cs:Base]
  389.         add     dx,102h         ; 102h
  390.         out     dx,al
  391.         inc     dx              ; 103h
  392.         mov     al,8ah
  393.         out     dx,al
  394.         inc     dx              ; 104h
  395.         in      ax,dx           ; TEMP0
  396.         mov     cx,ax
  397.         dec     dx              ; 103h
  398.         mov     al,8bh
  399.         out     dx,al
  400.         inc     dx              ; 104h
  401.         in      ax,dx           ; TEMP1
  402.         shl     cx,7
  403.         shr     ax,9
  404.         and     ax,7Fh
  405.         mov     dx,ax
  406.         and     dx,0Fh
  407.         mov     ax,cx
  408.         ret
  409. endp    U_ReadPos
  410.  
  411. ; AX-Mixer control
  412. ;  bit 0: 0=linein on, 1=linein off
  413. ;  bit 1: 0=output on, 1=output off
  414. ;  bit 2: 0=micin off, 1=micin on
  415. proc    U_ChangeInOut
  416.         mov     dx,[cs:Base]
  417.         out     dx,al
  418.         ret
  419. endp    U_ChangeInOut
  420.  
  421. ; The only reason I do it this way is because I haven't figured out the dump
  422. ; RAM to DRAM via DMA yet.
  423. ;
  424. ; Dump sample to Ram
  425. ;   ES:BX - Max 64k sample to dump to RAM.
  426. ;   SI:DI - DRAM location to dump to.
  427. ;   CX    - Max bytes to dump.
  428. ;   AH    - Xor value for twos complement.  Should actually be negated, but
  429. ;           oh, well.
  430. ;
  431. ; Approximate time to dump 1 megabyte of samples to DRAM (assuming they were
  432. ; all loaded in memory) is 5 seconds.
  433. proc    U_DumpSampleToDRAM
  434.         mov     dx,[cs:Base]
  435.         add     dx,103h
  436.         mov     al,44h          ; Dump upper byte, only do it on carry from now
  437.         out     dx,al           ; on.
  438.         add     dx,2
  439.         push    ax
  440.         mov     ax,si
  441.         out     dx,al
  442.         pop     ax
  443.         sub     dx,2
  444. @@MainLoop:
  445.         mov     al,43h
  446.         out     dx,al
  447.         inc     dx
  448.         push    ax
  449.         mov     ax,di
  450.         out     dx,ax
  451.         pop     ax
  452.         dec     dx
  453.         add     di,1
  454.         jnc     @@DumpByte
  455.         inc     si
  456.         mov     al,44h
  457.         out     dx,al
  458.         add     dx,2
  459.         push    ax
  460.         mov     ax,si
  461.         out     dx,al
  462.         pop     ax
  463.         sub     dx,2
  464. @@DumpByte:
  465.         add     dx,4
  466.         mov     al,[es:bx]
  467.         xor     al,ah
  468.         inc     bx
  469.         out     dx,al
  470.         sub     dx,4
  471.         loop    @@MainLoop
  472.         ret
  473. endp    U_DumpSampleToDRAM
  474.  
  475. proc    U_DumpDRAMToMemory
  476.         mov     dx,[cs:Base]
  477.         add     dx,103h
  478.         mov     al,44h          ; Dump upper byte, only do it on carry from now
  479.         out     dx,al           ; on.
  480.         add     dx,2
  481.         mov     ax,si
  482.         out     dx,al
  483.         sub     dx,2
  484. @@MainLoop:
  485.         mov     al,43h
  486.         out     dx,al
  487.         inc     dx
  488.         mov     ax,di
  489.         out     dx,ax
  490.         dec     dx
  491.         add     di,1
  492.         jnc     @@DumpByte
  493.         inc     si
  494.         mov     al,44h
  495.         out     dx,al
  496.         add     dx,2
  497.         mov     ax,si
  498.         out     dx,al
  499.         sub     dx,2
  500. @@DumpByte:
  501.         add     dx,4
  502.         in      al,dx
  503.         mov     [es:bx],al
  504.         inc     bx
  505.         sub     dx,4
  506.         loop    @@MainLoop
  507.         ret
  508. endp    U_DumpDRAMToMemory
  509.  
  510.  
  511. ; Carry set - No GUS
  512. ; No carry  - GUS at Base
  513. proc    U_DetectGUS
  514.         mov     [Word cs:Base],210h
  515. @@TestIt:
  516.         call    U_Probe
  517.         jnb     @@FoundIt
  518.         add     [Word cs:Base],10h
  519.         cmp     [Word cs:Base],270h
  520.         jb      @@TestIt
  521.         stc
  522. @@FoundIt:
  523.         ret
  524. endp    U_DetectGUS
  525.  
  526. proc    LoadDumpSample
  527.         mov     ah,48h
  528.         mov     bx,14848/4+1
  529.         int     21h
  530.         mov     [SampleSeg],ax
  531.  
  532.         mov     ax,3D00h
  533.         mov     dx,offset FName
  534.         int     21h
  535.         mov     bx,ax
  536.         push    ds
  537.         mov     ah,3Fh
  538.         mov     cx,14848
  539.         mov     dx,0
  540.         mov     ds,[SampleSeg]
  541.         int     21h
  542.         pop     ds
  543.  
  544.         mov     ax,3E00h
  545.         int     21h
  546.  
  547.         mov     es,[SampleSeg]
  548.         mov     bx,0
  549.         mov     cx,14848
  550.         mov     si,0
  551.         mov     di,0
  552.         mov     ah,10000000b
  553.         call    U_DumpSampleToDRAM
  554.         ret
  555. endp    LoadDumpSample
  556.  
  557. proc    LoadDumpSample2
  558.         mov     ah,48h
  559.         mov     bx,9900/4+1
  560.         int     21h
  561.         mov     [SampleSeg2],ax
  562.  
  563.         mov     ax,3D00h
  564.         mov     dx,offset FName2
  565.         int     21h
  566.         mov     bx,ax
  567.         push    ds
  568.         mov     ah,3Fh
  569.         mov     cx,9900
  570.         mov     dx,0
  571.         mov     ds,[SampleSeg2]
  572.         int     21h
  573.         pop     ds
  574.  
  575.         mov     ax,3E00h
  576.         int     21h
  577.  
  578.         mov     es,[SampleSeg2]
  579.         mov     bx,0
  580.         mov     cx,9900
  581.         mov     si,1
  582.         mov     di,0
  583.         mov     ah,0
  584.  
  585.         call    U_DumpSampleToDRAM
  586.         ret
  587. endp    LoadDumpSample2
  588.  
  589. Balance db      7
  590. Volume  dw      0d000h
  591. Mode    db      0
  592.  
  593. Start:
  594.         mov     ax,es
  595.         mov     bx,zzzzzseg
  596.         sub     bx,ax
  597.         add     bx,2
  598.         mov     ah, 4ah
  599.         int     21h
  600.  
  601.         mov     ax,MyData
  602.         mov     ds,ax
  603.  
  604.         call    U_DetectGUS
  605.         call    U_Reset
  606.         mov     al,0
  607.         call    U_ChangeInOut
  608.  
  609.         call    LoadDumpSample
  610.         call    LoadDumpSample2
  611.  
  612.         mov     ax,1
  613.         mov     bx,7
  614.         call    U_SetBalance
  615.         mov     bx,1
  616.         mov     ax,8448
  617.         call    U_SetFreq
  618.         mov     ax,1
  619.         mov     bx,0ffffh
  620.         call    U_SetVolume
  621.         mov     [Word cs:SampleBegin],0
  622.         mov     [Word cs:SampleBegin+2],0
  623.         mov     [Word cs:SampleStart],0
  624.         mov     [Word cs:SampleStart+2],0
  625.         mov     [Word cs:SampleEnd],14847
  626.         mov     [Word cs:SampleEnd+2],0
  627.         mov     ax,1
  628.         mov     bx,00001000b
  629.         call    U_StartVoice
  630.         mov     ax,0
  631.         mov     bx,7
  632.         call    U_SetBalance
  633.  
  634. (continued next message....)
  635.  
  636.  
  637. Date: 01-16-93 (04:34)              Number: 1249 of 1256
  638.   To: RICKY LACY                    Refer#: NONE
  639. From: PHAT H TRAN <GWINNETT.COM       Read: NO
  640. Subj: Re: GUS PROGRAMMING INFO.     Status: RECEIVER ONLY
  641. Conf: INTERNET-MAIL (237)        Read Type: GENERAL (A) (+)
  642.  
  643.         mov     bx,0
  644.         mov     ax,27186
  645.         call    U_SetFreq
  646.         mov     ax,0
  647.         mov     bx,[cs:Volume]
  648.         call    U_SetVolume
  649.         mov     [Word cs:SampleBegin],0
  650.         mov     [Word cs:SampleBegin+2],1
  651.         mov     [Word cs:SampleStart],0
  652.         mov     [Word cs:SampleStart+2],1
  653.         mov     [Word cs:SampleEnd],9899
  654.         mov     [Word cs:SampleEnd+2],1
  655.         mov     ax,0
  656.         mov     bx,00001000b
  657.         call    U_StartVoice
  658.  
  659. @@KeyLoop:
  660.         mov     ah,0
  661.         int     16h
  662.         cmp     al,'='
  663.         jnz     @@CheckNext
  664.         cmp     [Byte cs:Balance],15
  665.         jz      @@KeyLoop
  666.         inc     [Byte cs:Balance]
  667.         mov     ax,1
  668.         mov     bl,[cs:Balance]
  669.         call    U_SetBalance
  670.         jmp     @@KeyLoop
  671. @@CheckNext:
  672.         cmp     al,'-'
  673.         jnz     @@CheckVolUp
  674.         cmp     [Byte cs:Balance],0
  675.         jz      @@KeyLoop
  676.         dec     [Byte cs:Balance]
  677.         mov     ax,1
  678.         mov     bl,[cs:Balance]
  679.         call    U_SetBalance
  680.         jmp     @@KeyLoop
  681. @@CheckVolUp:
  682.         cmp     al,'2'
  683.         jnz     @@CheckVolDown
  684.         add     [Word cs:Volume],500
  685.         jnc     @@SetVol
  686.         mov     [Word cs:Volume],0ffffh
  687. @@SetVol:
  688.         mov     ax,0
  689.         mov     bx,[cs:Volume]
  690.         call    U_SetVolume
  691.         jmp     @@KeyLoop
  692. @@CheckVolDown:
  693.         cmp     al,'1'
  694.         jnz     @@CheckSpace
  695.         sub     [Word cs:Volume],500
  696.         jnc     @@SetVol2
  697.         mov     [Word cs:Volume],0
  698. @@SetVol2:
  699.         mov     ax,0
  700.         mov     bx,[cs:Volume]
  701.         call    U_SetVolume
  702.         jmp     @@KeyLoop
  703. @@CheckSpace:
  704.         cmp     al,' '
  705.         jnz     @@CheckQuit
  706.         xor     [Byte Mode],00000011b
  707.         mov     ax,1
  708.         mov     bl,[Mode]
  709.         call    U_SetLoopMode
  710.         jmp     @@KeyLoop
  711.  
  712. @@CheckQuit:
  713.         cmp     al,27
  714.         jnz     @@KeyLoop
  715.  
  716.         mov     ax,0
  717.         call    U_StopVoice
  718.         mov     ax,1
  719.         call    U_StopVoice
  720.  
  721.         mov     ah,49h
  722.         mov     es,[SampleSeg]
  723.         int     21h
  724.         mov     ah,49h
  725.         mov     es,[SampleSeg2]
  726.         int     21h
  727.         mov     ax,4C00h
  728.         int     21h
  729.  
  730. segment MyData
  731.  
  732. SampleSeg       dw      ?
  733. SampleSeg2      dw      ?
  734. FName           db      's',0
  735. FName2          db      'orchhit',0
  736.  
  737. ends    MyData
  738.  
  739. segment zzzzzseg
  740.         db      16 dup (?)
  741. ends    zzzzzseg
  742.  
  743.          end     Start
  744.  
  745.  
  746.